﻿#ifndef FINSTCP_H
#define FINSTCP_H

#include <QObject>
#include <QHostAddress>
#include <QUdpSocket>
#include <QDebug>
#include <QTimer>
#include <QTime>
#include "TcpClient.h"
#include "PLCClientBase.h"

class FinsTcp : public PLCClientBase
{
    Q_OBJECT
public:
    explicit FinsTcp(const QString& name = "", QObject *parent = nullptr);
    virtual ~FinsTcp();
public:
    void onStateChanged(ComState state);
protected:
    virtual void processData(const PLCRequestData& requestData){}
//    virtual void reconnect() override{}
    void initCom() override;
    void sendReadData(const PLCRequestData& data) override;
    void sendWriteData(const PLCRequestData& data) override;
private:
    QString getHandShakeCommand();
    QString getReadHoldRegisterCommand(int startAddr, int length);
    QString getReadCoilsRegisterCommand(int startAddr, int length);
    QString getReadInputRegisterCommand(int startAddr, int length);
    QString getWriteHoldRegisterCommand(int startAddr, int length, QList<ModbusValue> vData);
    QString getWriteCoilsRegisterCommand(int startAddr, int length, QList<ModbusValue> vData);
    QString getWriteInputRegisterCommand(int startAddr, int length, QList<ModbusValue> vData);
//    inline QList<qint16> transToListInt(const QByteArray &buf);
//    inline QList<float> transToListFloat(const QByteArray &buf);
    void onReceiveData(const QByteArray& data);
    TcpClient *mTcpClient;
};

#endif // FINSTCP_H
